// yb_mingpian/pages/goods/search/search.js
var t = getApp(),
  core = t.requirejs("core"),
  e = t.requirejs("check");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keywords:"",
    list:[]
  },
  /**
    *搜索查询
    * @param  keywords  搜索关键字
    * @return array
    */
  bindSearch: function (t) {
    wx.navigateTo({
      url: '/yb_mingpian/pages/goods/home/home?fromsearch=1&key=' + this.data.keywords,
    })
  },
  choose:function(e){ 
    wx.navigateTo({
      url: '/yb_mingpian/pages/goods/home/home?fromsearch=1&key=' + e.currentTarget.dataset.name,
    })
  },
  remove:function(e){
    let that = this 
    core.get("User/DelSearchLog", {
      uid: t.getCache("userinfo").uid,
      id: e.currentTarget.dataset.id
    }, function (a) {
      if (a.code == 0){
        that.data.list.splice(e.currentTarget.dataset.index, 1);
        that.setData({
          list: that.data.list,
        })
      }else{
        core.alert(a.msg)
      }
    })
  },
  removeAll:function(){
    let that = this
    core.get("User/DelSearchLog", {
      uid: t.getCache("userinfo").uid,
      id: ''
    }, function (a) {
      if (a.code == 0) { 
        that.setData({
          list: [],
        })
      } else {
        core.alert(a.msg)
      }
    })
  },
  /**
   * 动态获取焦点
   */
  inputing: function (t) {
    var inputing = e.trim(t.detail.value);
    this.setData({
      keywords: inputing
    })
  },
  /**
   * 放大镜获取input框中的value值
   */
  icon: function (e) {
    wx.navigateTo({
      url: '/yb_mingpian/pages/goods/home/home?fromsearch=1&key='+this.data.keywords,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  let that = this
    core.get("User/GetSearchLog", { 
      uid: t.getCache("userinfo").uid
    }, function (a) { 
      that.setData({
        list: a.info,
      })
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})